require("TSLib")

local AppName = "com.xxxx.hlwzf.sj49you"
local width,height = getScreenSize();



function _点阵初始化()
	组队战斗点阵 ={
		["开始战斗"]={   -- 开始战斗按钮出来的时候 队友是 “已准备”状态
			{  493,  187, 0xfffbaa},
			{  457,  206, 0xffeb06},
			{  431,  208, 0xfbea15},
			{  405,  215, 0xfaeb00},
			{  449,  212, 0xfde901},
			{  518,  185, 0xffff9b},
			{  510,  209, 0xffec00},
		},
		["战斗结束"]={   -- 战斗结束后 找到 宝箱的点
			{  702,  537, 0x502b1a},
			{  697,  527, 0x4e6269},
			{  736,  515, 0x764723},
			{  741,  571, 0x471c23},
			{  761,  508, 0x592909},
		},
		["继续组队"]= {  -- 继续战斗就是找文字
			{  114,  852, 0xffffff},
			{  124,  855, 0xfdfcfc},
			{  124,  847, 0xffffff},
			{  158,  851, 0xffffff},
			{  191,  854, 0xffffff},
			{  220,  856, 0xccc9c7},
			{  237,  867, 0xffffff},
		},
		["葫芦娃1"]={  
			{  563,  674, 0xfffffe},
			{  501,  657, 0xfefdf8},
			{  421,  732, 0xf4efbe},
			{  437,  804, 0xffffff},
			{  578,  806, 0xfefefa},
		},
		["葫芦娃2"]={
			{  776,  657, 0xfffffd},
			{  845,  687, 0xfefef8},
			{  869,  746, 0xf9f6d3},
			{  850,  802, 0xfefefc},
			{  688,  757, 0xfcfbf0},
		},
		["葫芦娃3"]={
			{ 1048,  660, 0xfcfbf2},
			{ 1106,  686, 0xfdfdf7},
			{ 1129,  743, 0xeae4ae},
			{  961,  737, 0xeee7a0},
			{  982,  806, 0xffffff},
		}
		-- todo 还有升级 以及 点击自动匹配的 功能 ，还有一个是防止有人搞事情，必须自动匹配四娃或者五娃的

	}

	组队战斗点击 ={
		["开始战斗"]={{ 1427,  780, 0xfffbc7},},
		["战斗结束"]={{ 1435,  765, 0xfffbc7},},
		["继续组队"]= {{  174,  762, 0xfffbcb},},
		["葫芦娃1"]={ {   514,  744, 0x94825f},},
		["葫芦娃2"]={{  782,  747, 0x4e254e },},
		["葫芦娃3"]={{  1039,  739, 0xb97c6c },}
	}
end


--初始化屏幕
function _InitScreenSize()
	if width == 1600 and height == 900 then
		toast("屏幕初始化成功，官方支持雷电模拟器",1);
		_点阵初始化();
	else
		dialog("您的模拟器尺寸暂未支持,请设置为1600x900", 0)
		lua_exit();
	end
end

--初始化
function _Init()
	init(AppName,0);
	_InitScreenSize()
end



--游戏主流程
function _GameFlow()
	while (true) do
		if _运行(AppName) then
			mSleep(10000);
			_点击({1,1});
		end
		toast("轮询点击中",1)
		_表找色点击(组队战斗点阵,组队战斗点击);
	end
end


-- 自动战斗的场景
function autoFight()
	if multiColor({{  493,  187, 0xfffbaa},
			{  457,  206, 0xffeb06},
			{  431,  208, 0xfbea15},
			{  405,  215, 0xfaeb00},
			{  449,  212, 0xfde901},
			{  518,  185, 0xffff9b},
			{  510,  209, 0xffec00},},90,false) == true then
		tap(1427,  780)
		mSleep(200)
		toast("开始战斗")
		mSleep(200)
	elseif  multiColor({{  702,  537, 0x502b1a},
			{  697,  527, 0x4e6269},
			{  736,  515, 0x764723},
			{  741,  571, 0x471c23},
			{  761,  508, 0x592909},},90,false) == true then
		tap(1435,  765)
		mSleep(50)
		toast("战斗结束")
		mSleep(3000)
	elseif multiColor({{  114,  852, 0xffffff},
			{  124,  855, 0xfdfcfc},
			{  124,  847, 0xffffff},
			{  158,  851, 0xffffff},
			{  191,  854, 0xffffff},
			{  220,  856, 0xccc9c7},
			{  237,  867, 0xffffff},},90,false) == true then
		tap(174,  762)
		mSleep(200)
		toast("继续战斗")
	elseif multiColor({  
			{  563,  674, 0xfffffe},
			{  501,  657, 0xfefdf8},
			{  421,  732, 0xf4efbe},
			{  437,  804, 0xffffff},
			{  578,  806, 0xfefefa},},90,false) == true then
		tap( 514,  744)
		mSleep(200)
		toast("葫芦娃1释放技能")
	elseif multiColor({
			{  776,  657, 0xfffffd},
			{  845,  687, 0xfefef8},
			{  869,  746, 0xf9f6d3},
			{  850,  802, 0xfefefc},
			{  688,  757, 0xfcfbf0},
			},90,false) == true then
		tap(782,  747)
		mSleep(200)
		toast("葫芦娃2释放技能")
	elseif multiColor({
			{ 1048,  660, 0xfcfbf2},
			{ 1106,  686, 0xfdfdf7},
			{ 1129,  743, 0xeae4ae},
			{  961,  737, 0xeee7a0},
			{  982,  806, 0xffffff},},90,false) == true then
		tap(1039,  739)
		mSleep(200)
		toast("葫芦娃3释放技能")
	elseif multiColor({
			{  773,  285, 0xffffff},
			{  775,  290, 0xffffff},
			{  774,  314, 0xffffff},
			{  856,  297, 0xffffff},
			{  898,  302, 0xffffff},
			{  912,  298, 0xffffff},
			},90,false) == true then
		tap( 837,  298)
		mSleep(200)
		toast("自动匹配")
	elseif multiColor({
			{  818,  187, 0xffa129},
			{  682,  156, 0xffee63},
			{  656,  198, 0xcf6e6f},
			{  743,  195, 0xffa229},
			{  848,  188, 0xffa229},
			{  891,  181, 0xffb833},
			{  929,  207, 0xffa42b},
			{  954,  196, 0xed8f90},
			},90,false) == true then
		tap( 812,  449)
		mSleep(200)
		toast("玩家升级")
	else  
		--toast("没有找到相关的点",1)
		mSleep(200)
	end
end


-- 自动务农
function autoFarm(...)

end




function  _GameAuto()
	while (true) do
		autoFight()  --自动战斗
		autoFarm()   --自动进行种菜
	end
end






_Init();
_GameAuto();